# Maintainer: Peter Budai <peterbudai at hotmail.com>

# This package cannot be build with installed libgdiplus package 
# as it doesnt contain reference for GdipFontFamilyCachedGenericSansSerif

_realname=gnuplot
_wx_basever=3.0
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.4.5
pkgrel=1
pkgdesc="Plotting package which outputs to X11, PostScript, PNG, GIF, and others (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='http://www.gnuplot.info/'
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libcaca"
         "${MINGW_PACKAGE_PREFIX}-libcerf"
         "${MINGW_PACKAGE_PREFIX}-libgd"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw"
)
options=('strip' 'staticlibs')
source=("https://downloads.sourceforge.net/sourceforge/${_realname}/${_realname}-${pkgver}.tar.gz"
        "01-gnuplot.patch")
sha256sums=('66f679115dd30559e110498fc94d926949d4d370b4999a042e724b8e910ee478'
            '9b8af2d8eb24f0e8048a388949d8905a79b69208cf7eadd34a763a0c582b8f9e')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/01-gnuplot.patch

  sed -i "s/AC_PATH_PROG(WX_CONFIG, wx-config,/AC_PATH_PROG(WX_CONFIG, wx-config-${_wx_basever},/" configure.ac

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --without-lua \
      --with-caca \
      --with-qt=no \
      --with-readline=gnu \
      --with-bitmap-terminals \
      --disable-x11-mbfonts \
      --disable-x11-external \
      --disable-raise-console

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"
}
